package com.pluto.order.controller;

import com.pluto.order.bean.Order;
import com.pluto.order.properties.OrderProperties;
import com.pluto.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

// 自动刷新配置
@RefreshScope
@RestController
public class OrderController {

	@Autowired
	private OrderService orderService;

	@Autowired
	private OrderProperties orderProperties;


	@GetMapping("/config")
	public String config() {
		return "orderTimeout: " + orderProperties.getTimeOut() + "and orderAutoConfirm: " +
				orderProperties.getAutoConfirm() + " and dbUrl: " + orderProperties.getDbUrl();
	}

	@GetMapping("/create")
	public Order createOrder(@RequestParam("userId") Long userId,
	                         @RequestParam("productId") String productId) {
		return orderService.createOrder(productId, userId);
	}
}
